import java.util.LinkedHashSet;
import java.util.Set;

// 402
public class P74 {
	
	private static long digitFactorial(long n) {
		String num = String.valueOf(n);
		long x = 0;
		for (int i = 0; i < num.length(); i++) {
			x += Util.factorial(Integer.parseInt(num.substring(i, i + 1)));
		}
		
		return x;
	}
	
	private static Set<Long> digitFactorialSet(long n) {
		Set<Long> set = new LinkedHashSet<Long>();
		
		set.add(n);
		
		while (true) {
			n = digitFactorial(n);
			if (set.contains(n)) {
				break;
			}
			set.add(n);
		} 
		
		return set;
	}
	
	public static void main(String[] args) {
		int count = 0;
		for (int i = 2; i < 1000000; i++) {
			if (digitFactorialSet(i).size() == 60) {
				count++;
			}
			System.out.println(i);
		}
		
		System.out.println(count);
	}
}
